/*******************************************************************************
 * Software Name : Android Simple Downloader
 *
 * Copyright © 2012 Rinvay Tang
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.rinvay.network.http;

import java.util.HashMap;

/**
 * http 请求类
 * @author tyf
 * @date 2012-3-12
 * @time 上午10:42:40
 */
public class HttpRequest {
	
	/**
	 * http url string
	 */
	private String url;
	
	/**
	 * http request method eg:GET, POST
	 */
	private String method = null;
	
	/**
	 * data in a POST http request
	 */
	private byte [] data = null;
	
	/**
	 * http headers, eg: user-agent or other
	 */
	private HashMap<String, String> headers = null;
	
	/**
	 * default GET http request
	 * @param url
	 */
	public HttpRequest(String url) {
		this(url, "GET");
	}
	
	/**
	 * default POST http request
	 * @param url
	 * @param data
	 */
	public HttpRequest(String url, byte [] data) {
		this(url, "POST", data);
	}
	
	public HttpRequest(String url, String method) {
		this(url, method, null);
	}
	
	public HttpRequest(String url, String method, byte [] data) {
		this.url = url;
		this.method = method;
		this.data = data;
	}
	
	
	public String getUrl() {
		return url;
	}
	
	public String getMethod() {
		return method;
	}
	
	public byte [] getData() {
		return data;
	}
	
	public String getHeader(String name) {
		return headers.get(name);
	}
	
	public void setHeader(String name, String value) {
		if(headers == null) {
			headers = new HashMap<String, String>();
		}
		headers.put(name, value);
	}
	
	public HashMap<String, String> getHeaders() {
		return headers;
	}
	
	public void setHeaders(HashMap<String, String> headers) {
		if(headers == null || headers.size() <=0) {
			return;
		}
		this.headers.putAll(headers);
	}

}
